Compare mean, median, COV, std


In [ ]:


In [17]:
drive_path = 'c:/'
import numpy as np
import pandas as pd
import os
import sys
import matplotlib.pyplot as plt
from scipy.stats import ks_2samp
from scipy.stats import anderson_ksamp
from scipy.stats import kruskal
from scipy.stats import variation
%matplotlib
import seaborn as sns


Using matplotlib backend: Qt4Agg

In [18]:
comp=pd.read_csv('C:\Users\Annie\Documents\Data\Ca_Imaging\GoodFiles\\fullpeak.csv')
comp_sorted=comp.reindex_axis(comp.mean().sort_values().index, axis=1)
comp_labels=pd.DataFrame(comp.Mouse)
comp_group=pd.DataFrame(comp.Group)
tmp=[comp_group,comp_labels,comp_sorted]
composite_full=pd.concat(tmp,axis=1)
cfull=pd.melt(composite_full,('Group','Mouse'),var_name="Odor")
# cfull['Mouse'] = cfull['Mouse'].apply(lambda x: x.split('_')[0])
# composite_full['Mouse']=composite_full['Mouse'].apply(lambda x:x.split('_')[0])

In [4]:
cfull


Out[4]:
Group Mouse Odor value
0 Control 160321_1 MS01 0.015671
1 Control 160321_1 MS01 -0.034636
2 Control 160321_1 MS01 -0.044179
3 Control 160321_1 MS01 0.146939
4 Control 160321_1 MS01 0.268299
5 Control 160321_1 MS01 0.111727
6 Control 160321_1 MS01 0.182874
7 Control 160321_1 MS01 0.086948
8 Control 160321_1 MS01 0.106260
9 Control 160321_1 MS01 0.154366
10 Control 160321_1 MS01 0.020829
11 Control 160321_1 MS01 -0.093950
12 Control 160321_1 MS01 0.091192
13 Control 160321_1 MS01 0.369279
14 Control 160321_1 MS01 0.378874
15 Control 160321_1 MS01 0.080862
16 Control 160321_1 MS01 0.117418
17 Control 160321_1 MS01 0.065225
18 Control 160321_2 MS01 0.108320
19 Control 160321_2 MS01 0.179008
20 Control 160321_2 MS01 0.116572
21 Control 160321_2 MS01 0.191554
22 Control 160321_2 MS01 0.203699
23 Control 160321_2 MS01 0.073796
24 Control 160321_2 MS01 0.117774
25 Control 160321_2 MS01 0.146185
26 Control 160321_2 MS01 0.114494
27 Control 160321_2 MS01 0.215789
28 Control 160321_2 MS01 0.188919
29 Control 160321_2 MS01 0.157538
... ... ... ... ...
12915 Hexanal 160626_1 EB 0.322258
12916 Hexanal 160626_1 EB 0.910795
12917 Hexanal 160626_1 EB 1.243407
12918 Hexanal 160626_1 EB 1.029620
12919 Hexanal 160626_2 EB 2.129344
12920 Hexanal 160626_2 EB 2.526371
12921 Hexanal 160626_2 EB 2.787493
12922 Hexanal 160626_2 EB 2.872082
12923 Hexanal 160626_2 EB 2.623944
12924 Hexanal 160626_2 EB 3.141432
12925 Hexanal 160626_2 EB 3.826471
12926 Hexanal 160626_2 EB 3.415339
12927 Hexanal 160626_2 EB 4.020523
12928 Hexanal 160626_2 EB 3.575100
12929 Hexanal 160626_2 EB 3.256687
12930 Hexanal 160626_2 EB 2.497531
12931 Hexanal 160626_2 EB 3.091349
12932 Hexanal 160626_2 EB 2.897091
12933 Hexanal 160626_2 EB 3.002847
12934 Hexanal 160626_2 EB 1.644408
12935 Hexanal 160626_2 EB 2.301010
12936 Hexanal 160626_2 EB 3.717106
12937 Hexanal 160626_2 EB 3.135329
12938 Hexanal 160626_2 EB 2.555852
12939 Hexanal 160626_2 EB 2.778626
12940 Hexanal 160626_2 EB 3.687546
12941 Hexanal 160626_2 EB 4.049244
12942 Hexanal 160626_2 EB 4.306552
12943 Hexanal 160626_2 EB 3.434703
12944 Hexanal 160626_2 EB 3.634535

12945 rows × 4 columns


In [19]:
colors={'160321':'r', '160421':'r', '160502':'r', '160503':'r', '160420':'r',
       '160517':'b', '160525':'b', '160620':'b', '160621':'b', '160622':'b', '160626':'b',
       '160330':'g', '160328':'g', '160428':'g', '160429':'g', '160325':'g', '160401':'g'}

In [20]:
cctrl=cfull[cfull.Mouse.isin(['160321','160421','160502','160503','160420'])]
hexfull=cfull[cfull.Mouse.isin(['160517', '160525', '160620', '160621', '160622', '160626'])]
msfull=cfull[cfull.Mouse.isin(['160330', '160328', '160428', '160429', '160325','160401'])]

In [21]:
cfc=composite_full[composite_full.Mouse.isin(['160321','160421','160502','160503','160420'])]
cfh=composite_full[composite_full.Mouse.isin(['160517', '160525', '160620', '160621', '160622', '160626'])]
cfm=composite_full[composite_full.Mouse.isin(['160330', '160328', '160428', '160429', '160325','160401'])]

In [22]:
odorlist=['THA', 'MS01', 'Blank', 'AP', 'MS10', 'MS05',
       'IAA05', 'IAA01', 'PA', 'IAA10', 'Hexanone', 'Hexanal10',
       'Hexanal01', 'Hexanal05', 'EB']

Calculate zscores for each group


In [23]:
from scipy.stats import zscore
from scipy.stats import nanmean
from scipy.stats import nanstd
# zscore(composite_full[composite_full.Mouse==x][y])

In [34]:
zscores=pd.DataFrame([])

for x in composite_full.Mouse.unique():
    tmp=pd.DataFrame([])
    for y in odorlist:
        v=(composite_full[composite_full.Mouse==x][y])
        a=pd.DataFrame((v - nanmean(v)) / nanstd(v))
        a=a.reset_index(drop=True)
        a.columns=[y]
        tmp=pd.concat([tmp,a],axis=1)
    b=pd.DataFrame(composite_full[composite_full.Mouse==x]['Mouse'])
    b=b.reset_index(drop=True)
    c=pd.DataFrame(composite_full[composite_full.Mouse==x]['Group'])
    c=c.reset_index(drop=True)
    tmp=pd.concat([c,tmp],axis=1)
    zscores=zscores.append(tmp)

In [32]:
zscores[zscores.Group=='Mint']['AP']


Out[32]:
0    -0.615288
1     0.903824
2     0.715327
3    -1.364441
4    -1.014849
5    -1.326433
6    -0.714424
7    -0.058275
8     0.822923
9    -0.748909
10   -1.358461
11   -0.122966
12   -0.382172
13    0.369332
14    1.730979
15         NaN
16   -0.899317
17    0.232029
18   -0.729886
19    2.044908
20    0.773271
21    0.702630
22    1.040198
0    -0.027423
1    -0.195629
2     1.050387
3    -1.297867
4     0.834173
5    -0.224580
6    -1.110993
        ...   
13    0.341740
14   -1.451162
15    0.336718
16    0.021488
0    -2.021330
1    -0.668554
2     0.405857
3     0.000229
4    -0.622962
5     0.396640
6     0.838872
7    -0.105340
8    -0.289195
9    -0.188033
10   -0.228417
11    0.395511
12   -0.224052
13   -0.775834
14    0.358138
15   -0.195243
16   -0.224691
17    1.810836
18    2.944039
19   -0.423262
20    0.773096
21   -1.210640
22   -0.461908
23    1.340388
24   -1.216957
25   -0.407187
Name: AP, dtype: float64

In [42]:
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.distplot(zscores[zscores.Group=='Control']['IAA10'].dropna(),color='r');
sns.distplot(zscores[zscores.Group=='Mint']['IAA10'].dropna(),color='g');
sns.distplot(zscores[zscores.Group=='Hexanal']['IAA10'].dropna(),color='b');

In [27]:
zmelt=pd.melt(zscores,"Group",var_name="Odor")

In [24]:
groupcolors={'Control':'r','Mint':'g','Hexanal':'b'}

In [30]:
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=zmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('Zscore', fontsize=48);
plt.title('Zscore', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [319]:
sns.distplot(zscores[zscores.Group=='Control']['Hexanal01'], hist=False, color="r", kde_kws={"shade": True});
sns.distplot(zscores[zscores.Group=='Mint']['Hexanal01'], hist=False, color="g", kde_kws={"shade": True});
sns.distplot(zscores[zscores.Group=='Hexanal']['Hexanal01'], hist=False, color="b", kde_kws={"shade": True});

In [11]:
means=pd.DataFrame([])
for x in composite_full.Mouse.unique():
    tmp=pd.DataFrame([])
    for y in odorlist:
        a=composite_full[composite_full.Mouse==x][y].mean()
        m=pd.DataFrame({y:[a]})
        tmp=pd.concat([tmp,m],axis=1)
    b=pd.DataFrame({'Mouse':[x]})
    c=pd.DataFrame({'Group':[composite_full[composite_full.Mouse==x]['Group'].iloc[0]]})
#     c=c.reset_index(drop=True)
    tmp=pd.concat([c,tmp],axis=1)
    means=means.append(tmp)

In [12]:
meanmelt=pd.melt(means,"Group",var_name="Odor")

In [15]:
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=meanmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('Mean', fontsize=48);
plt.title('Mean', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [25]:
medians=pd.DataFrame([])
for x in composite_full.Mouse.unique():
    tmp=pd.DataFrame([])
    for y in odorlist:
        a=composite_full[composite_full.Mouse==x][y].median()
        m=pd.DataFrame({y:[a]})
        tmp=pd.concat([tmp,m],axis=1)
    b=pd.DataFrame({'Mouse':[x]})
    c=pd.DataFrame({'Group':[composite_full[composite_full.Mouse==x]['Group'].iloc[0]]})
#     c=c.reset_index(drop=True)
    tmp=pd.concat([c,tmp],axis=1)
    medians=medians.append(tmp)

In [26]:
medianmelt=pd.melt(medians,"Group",var_name="Odor")

In [27]:
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=medianmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('Median', fontsize=48);
plt.title('Median', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [ ]:


In [275]:
stds=pd.DataFrame([])
for x in composite_full.Mouse.unique():
    tmp=pd.DataFrame([])
    for y in odorlist:
        a=composite_full[composite_full.Mouse==x][y].std()
        m=pd.DataFrame({y:[a]})
        tmp=pd.concat([tmp,m],axis=1)
    b=pd.DataFrame({'Mouse':[x]})
    c=pd.DataFrame({'Group':[composite_full[composite_full.Mouse==x]['Group'].iloc[0]]})
#     c=c.reset_index(drop=True)
    tmp=pd.concat([c,tmp],axis=1)
    stds=stds.append(tmp)

In [276]:
stdmelt=pd.melt(stds,"Group",var_name="Odor")

In [277]:
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=stdmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('STD', fontsize=48);
plt.title('STD', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [ ]:

Plot everything by mouse


In [330]:
#Plot everything by mouse
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Mouse',palette=colors,data=cfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Integral', fontsize=48);
plt.title('By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-330-fc5374bcb9e2> in <module>()
      3 sns.set_context("talk", font_scale=1.8);
      4 plt.figure(figsize=(45, 20));
----> 5 ax=sns.boxplot(x='Odor',y='value',hue='Mouse',palette=colors,data=cfull)
      6 ax.legend_.remove()
      7 sns.despine()

C:\Users\Annie\Anaconda2\lib\site-packages\seaborn\categorical.pyc in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, fliersize, linewidth, whis, notch, ax, **kwargs)
   2173     plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
   2174                           orient, color, palette, saturation,
-> 2175                           width, fliersize, linewidth)
   2176 
   2177     if ax is None:

C:\Users\Annie\Anaconda2\lib\site-packages\seaborn\categorical.pyc in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, fliersize, linewidth)
    424                  width, fliersize, linewidth):
    425 
--> 426         self.establish_variables(x, y, hue, data, orient, order, hue_order)
    427         self.establish_colors(color, palette, saturation)
    428 

C:\Users\Annie\Anaconda2\lib\site-packages\seaborn\categorical.pyc in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
    152 
    153             # Figure out the plotting orientation
--> 154             orient = self.infer_orient(x, y, orient)
    155 
    156             # Option 2a:

C:\Users\Annie\Anaconda2\lib\site-packages\seaborn\categorical.pyc in infer_orient(self, x, y, orient)
    347         elif is_not_numeric(y):
    348             if is_not_numeric(x):
--> 349                 raise ValueError(no_numeric)
    350             else:
    351                 return "h"

ValueError: Neither the `x` nor `y` variable appears to be numeric.

In [99]:
#Plot everything by mouse
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.swarmplot(x='Odor',y='value',hue='Mouse',palette=colors,data=cfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak DF/F', fontsize=48);
plt.title('By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [351]:
#Plot control by mouse
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot('Odor','value',hue='Mouse',data=cctrl)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('By Mouse - Control', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [352]:
#Plot everything by mouse - Hexanal
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot('Odor','value',hue='Mouse',data=hexfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('By Mouse - Hexanal', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [353]:
#Plot everything by mouse - Mint
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot('Odor','value',hue='Mouse',data=msfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('By Mouse - Mint', fontsize=55);
plt.xlabel('Odor', fontsize=48);

Means


In [9]:
cdf=[]
for x in cfc.Mouse.unique():
    cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
cmeandf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
cmeandf.columns=cfc.columns
cmeanmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")

mdf=[]
for x in cfm.Mouse.unique():
    mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
mmeandf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
mmeandf.columns=cfm.columns

hdf=[]
for x in cfh.Mouse.unique():
    hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
hmeandf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
hmeandf.columns=cfh.columns
full_mean=pd.melt(pd.concat([cmeandf,mmeandf,hmeandf],ignore_index=True),'Mouse',var_name='Odor')


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-fd2cc96061dc> in <module>()
      3     cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
      4 cmeandf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
----> 5 cmeandf.columns=cfc.columns
      6 cmeanmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")
      7 

C:\Users\Annie\Anaconda2\lib\site-packages\pandas\core\generic.pyc in __setattr__(self, name, value)
   2683         try:
   2684             object.__getattribute__(self, name)
-> 2685             return object.__setattr__(self, name, value)
   2686         except AttributeError:
   2687             pass

pandas\src\properties.pyx in pandas.lib.AxisProperty.__set__ (pandas\lib.c:44748)()

C:\Users\Annie\Anaconda2\lib\site-packages\pandas\core\generic.pyc in _set_axis(self, axis, labels)
    426 
    427     def _set_axis(self, axis, labels):
--> 428         self._data.set_axis(axis, labels)
    429         self._clear_item_cache()
    430 

C:\Users\Annie\Anaconda2\lib\site-packages\pandas\core\internals.pyc in set_axis(self, axis, new_labels)
   2633             raise ValueError('Length mismatch: Expected axis has %d elements, '
   2634                              'new values have %d elements' %
-> 2635                              (old_len, new_len))
   2636 
   2637         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 1 elements, new values have 17 elements

In [10]:
full_mean


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-5befe0f2a882> in <module>()
----> 1 full_mean

NameError: name 'full_mean' is not defined

In [279]:
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.pointplot('Odor','value',hue='Mouse',palette=colors,data=full_mean)
sns.despine()
plt.ylabel('Peak DF/F', fontsize=48);
plt.title('Mean, By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [ ]:


In [178]:


In [181]:



Out[181]:
Mouse Mean
0 160517 0.202578
1 160517 0.174359
2 160517 0.282034
3 160517 0.074394
4 160517 0.084072
5 160517 0.132455
6 160517 0.026838
7 160517 0.152396
8 160517 0.107700
9 160517 0.129484
10 160517 0.199730
11 160517 0.205829
12 160517 0.204539
13 160517 0.276089
14 160517 0.263289
15 160517 0.152796
16 160517 0.014208
17 160517 0.143471
18 160517 0.356650
19 160517 0.043189
20 160517 0.225102
21 160525 0.122464
22 160525 0.157107
23 160525 0.105191
24 160525 0.245960
25 160525 0.168111
26 160525 0.172553
27 160525 0.147849
28 160525 0.134845
29 160525 0.319380
... ... ...
339 160626 0.168338
340 160626 0.472677
341 160626 0.639406
342 160626 0.502097
343 160626 1.377059
344 160626 1.024115
345 160626 1.655063
346 160626 1.042272
347 160626 1.119279
348 160626 1.199992
349 160626 1.760510
350 160626 1.765566
351 160626 1.847226
352 160626 1.373974
353 160626 1.352353
354 160626 0.969210
355 160626 1.134219
356 160626 1.109174
357 160626 1.178214
358 160626 1.100854
359 160626 0.929194
360 160626 1.291236
361 160626 1.594152
362 160626 1.627045
363 160626 1.318785
364 160626 1.899250
365 160626 2.046839
366 160626 2.029860
367 160626 1.711172
368 160626 1.899989

369 rows × 2 columns


In [ ]:

Medians


In [16]:
cdf=[]
for x in cfc.Mouse.unique():
    cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].median(0,skipna=True))
cmeddf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
cmeddf.columns=cfc.columns
cmedmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")

mdf=[]
for x in cfm.Mouse.unique():
    mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].median(0,skipna=True))
mmeddf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
mmeddf.columns=cfm.columns

hdf=[]
for x in cfh.Mouse.unique():
    hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].median(0,skipna=True))
hmeddf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
hmeddf.columns=cfh.columns
full_med=pd.melt(pd.concat([cmeddf,mmeddf,hmeddf],ignore_index=True),'Mouse',var_name='Odor')


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-ac5f11699f06> in <module>()
      3     cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].median(0,skipna=True))
      4 cmeddf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
----> 5 cmeddf.columns=cfc.columns
      6 cmedmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")
      7 

C:\Users\Annie\Anaconda2\lib\site-packages\pandas\core\generic.pyc in __setattr__(self, name, value)
   2683         try:
   2684             object.__getattribute__(self, name)
-> 2685             return object.__setattr__(self, name, value)
   2686         except AttributeError:
   2687             pass

pandas\src\properties.pyx in pandas.lib.AxisProperty.__set__ (pandas\lib.c:44748)()

C:\Users\Annie\Anaconda2\lib\site-packages\pandas\core\generic.pyc in _set_axis(self, axis, labels)
    426 
    427     def _set_axis(self, axis, labels):
--> 428         self._data.set_axis(axis, labels)
    429         self._clear_item_cache()
    430 

C:\Users\Annie\Anaconda2\lib\site-packages\pandas\core\internals.pyc in set_axis(self, axis, new_labels)
   2633             raise ValueError('Length mismatch: Expected axis has %d elements, '
   2634                              'new values have %d elements' %
-> 2635                              (old_len, new_len))
   2636 
   2637         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 1 elements, new values have 17 elements

In [281]:
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.pointplot('Odor','value',hue='Mouse',palette=colors,data=full_med)
sns.despine()
plt.ylabel('Peak DF/F', fontsize=48);
plt.title('Median, By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [289]:



Out[289]:
Mouse Odor value
0 160321 THA 0.137798
1 160421 THA 0.096810
2 160502 THA 0.108563
3 160503 THA 0.176428
4 160420 THA 0.150987
5 160310 THA 1.261965
6 160330 THA 0.069513
7 160328 THA 0.390481
8 160428 THA 0.221489
9 160429 THA 0.146081
10 160325 THA 0.295490
11 160401 THA 0.192857
12 160517 THA 0.146055
13 160525 THA 0.101379
14 160620 THA 0.511665
15 160621 THA 0.199847
16 160622 THA 0.366532
17 160626 THA 0.653575
18 160321 MS 0.01 0.126235
19 160421 MS 0.01 0.078415
20 160502 MS 0.01 0.114379
21 160503 MS 0.01 0.219756
22 160420 MS 0.01 0.130730
23 160310 MS 0.01 1.429755
24 160330 MS 0.01 0.061813
25 160328 MS 0.01 0.407542
26 160428 MS 0.01 0.177892
27 160429 MS 0.01 0.088924
28 160325 MS 0.01 0.249406
29 160401 MS 0.01 0.109788
... ... ... ...
240 160330 Hexanal 0.05 0.185113
241 160328 Hexanal 0.05 0.810908
242 160428 Hexanal 0.05 0.197639
243 160429 Hexanal 0.05 0.347239
244 160325 Hexanal 0.05 0.454709
245 160401 Hexanal 0.05 0.423419
246 160517 Hexanal 0.05 0.452034
247 160525 Hexanal 0.05 0.417041
248 160620 Hexanal 0.05 1.271598
249 160621 Hexanal 0.05 0.264920
250 160622 Hexanal 0.05 0.620433
251 160626 Hexanal 0.05 1.605382
252 160321 EB 0.182283
253 160421 EB 0.272477
254 160502 EB 0.221886
255 160503 EB 0.301049
256 160420 EB 0.254961
257 160310 EB 2.046201
258 160330 EB 0.071947
259 160328 EB 0.943080
260 160428 EB 0.245750
261 160429 EB 0.299182
262 160325 EB 0.398232
263 160401 EB 0.280932
264 160517 EB 0.216629
265 160525 EB 0.222401
266 160620 EB 1.819728
267 160621 EB 0.150275
268 160622 EB 0.790037
269 160626 EB 2.568513

270 rows × 3 columns


In [ ]:


In [ ]:

STD and COV


In [282]:
#Individual Animal COV
cdf=[]
for x in cfc.Mouse.unique():
    cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].std(0,skipna=True))
cstddf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
cstddf.columns=cfc.columns
cstdmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")

mdf=[]
for x in cfm.Mouse.unique():
    mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].std(0,skipna=True))
mstddf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
mstddf.columns=cfm.columns

hdf=[]
for x in cfh.Mouse.unique():
    hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].std(0,skipna=True))
hstddf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
hstddf.columns=cfh.columns
full_std=pd.melt(pd.concat([cstddf,mstddf,hstddf],ignore_index=True),'Mouse',var_name='Odor')
full_cov=pd.concat([full_std.Mouse,full_std.Odor,full_std.value.div(full_mean.value,axis=0)],axis=1)

In [283]:
#Get Averages
c_ave=pd.DataFrame(cstddf[odorlist].div(cmeandf[odorlist]).mean())
c_ave.columns=['Control']
m_ave=pd.DataFrame(mstddf[odorlist].div(mmeandf[odorlist]).mean())
m_ave.columns=['Mint']
h_ave=pd.DataFrame(hstddf[odorlist].div(hmeandf[odorlist]).mean())
h_ave.columns=['Hexanal']

full_ave=pd.concat([c_ave,m_ave,h_ave],axis=1)
full_ave=full_ave.reset_index()
full_ave.columns=['Odor','Control','Mint','Hexanal']

avemelt=pd.melt(full_ave,'Odor')

In [284]:
#PLOT STUFF
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.pointplot('Odor','value',hue='Mouse',palette=colors,data=full_cov)
sns.despine()
plt.ylabel('COV', fontsize=48);
plt.title('COV, by Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [ ]:


In [37]:
#Get Composite COV
cfc_std=pd.DataFrame(cfc[odorlist].std(0,skipna=True))
cfc_mean=pd.DataFrame(cfc[odorlist].mean(0,skipna=True))
cfc_cov=cfc_std.div(cfc_mean)

mfc_std=pd.DataFrame(cfm[odorlist].std(0,skipna=True))
mfc_mean=pd.DataFrame(cfm[odorlist].mean(0,skipna=True))
mfc_cov=mfc_std.div(mfc_mean)

hfc_std=pd.DataFrame(cfh[odorlist].std(0,skipna=True))
hfc_mean=pd.DataFrame(cfh[odorlist].mean(0,skipna=True))
hfc_cov=hfc_std.div(hfc_mean)

cfc_cov.columns=['Control']
mfc_cov.columns=['Mint']
hfc_cov.columns=['Hexanal']

full=pd.concat([cfc_cov,mfc_cov,hfc_cov],axis=1)
full=full.reset_index()
full.columns=['Odor','Control','Mint','Hexanal']

fullmelt=pd.melt(full,'Odor')
fullmelt.head()
# cstdall.columns=cfc.columns

# mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].std(0,skipna=True))
# mstddf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
# mstddf.columns=cfm.columns

# hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].std(0,skipna=True))
# hstddf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
# hstddf.columns=cfh.columns
# full_std=pd.melt(pd.concat([cstddf,mstddf,hstddf],ignore_index=True),'Mouse',var_name='Odor')
# full_cov=pd.concat([full_std.Mouse,full_std.Odor,full_std.value.div(full_mean.value,axis=0)],axis=1)


Out[37]:
Odor variable value
0 THA Control 0.744257
1 MS 0.01 Control 0.828195
2 BLANK Control 0.868441
3 AP Control 0.820212
4 MS 0.1 Control 0.793777

In [382]:


In [44]:
#PLOT STUFF
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.pointplot('Odor','value',hue='variable',palette={'Control':'r','Hexanal':'b','Mint':'g'},data=fullmelt)
sns.despine()
plt.ylabel('COV', fontsize=48);
plt.title('COV, Complete', fontsize=55);
plt.xlabel('Odor', fontsize=48);

In [ ]:


In [ ]:


In [ ]: